package com.cxb.demotest.testEventBus;

import com.google.common.eventbus.Subscribe;
import java.time.Instant;
import org.springframework.stereotype.Component;

/**
 * @author Xbao
 * @description
 * @date 2022/8/18 9:58
 */
@Component
public class StockChangeEventListener {

  @Subscribe
  public void sendStockLargerNotice(CustomEvent event){
    System.out.println(event.getMaterialName() + "stock add：" + event.getQuantity());
    System.out.println(Instant.now() + "stockListener-->stockAddSubcriber" + ",threadName："+Thread.currentThread().getName());
    try {
      Thread.sleep(3000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }

  @Subscribe
  public void sendStockSmallerNotice(CustomEvent event){
    System.out.println(event.getMaterialName() + "stock reduce：" + event.getQuantity());
    System.out.println(Instant.now() + "stockListener-->stockReduceSubcriber" + ",threadName："+Thread.currentThread().getName());
  }

}
